using UnityEngine;

public class PlayEffectOnTrigger : MonoBehaviour
{
    [Tooltip("要播放的特效预制体或特效对象")]
    public ParticleSystem effectPrefab;

    private bool hasPlayed = false;

    private void OnTriggerEnter(Collider other)
    {
        if (hasPlayed) return;

        if (other.CompareTag("Player"))
        {
            hasPlayed = true;

            // 对玩家造成伤害
            SCT_TankMovement playerScript = other.GetComponent<SCT_TankMovement>();
            if (playerScript != null)
            {
                playerScript.Damage(200);
            }

            // 播放特效
            if (effectPrefab != null)
            {
                effectPrefab.Play();
            }

            // 播放音效
            AudioSource audio = GetComponent<AudioSource>();
            if (audio != null)
            {
                audio.Play();
            }

            // 启动延迟禁用
            Invoke(nameof(DisableSelf), 0.5f);
        }
    }

    private void DisableSelf()
    {
        gameObject.SetActive(false);
    }
}
